package com.hzye.framework.common.conversion;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.hzye.framework.common.util.StringUtil;


/**
	 * 
	 */
public class DatePropertyEditor extends PropertyEditorSupport {
	private String format = "yyyy-MM-dd"; // 缺省

	public DatePropertyEditor(String format) {
		this.format = format;
	}

	public DatePropertyEditor() {
		this.format = "yyyy-MM-dd";
	}

	public void setFormat(String format) {
		this.format = format;
	}

	public void setAsText(String text) throws IllegalArgumentException {
		if (text != null && StringUtil.isNotEmpty(text)) {
			try {
				setValue(new Date((new SimpleDateFormat(this.format).parse(text)).getTime()));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
	}

}
